package com.logistics.modules.warehouseManagement.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.logistics.modules.warehouseManagement.entity.RepositoryEntity;
import com.logistics.modules.warehouseManagement.service.RepositoryService;
import com.logistics.common.utils.PageUtils;
import com.logistics.common.utils.R;



/**
 * 
 *
 * @author HURRICANE
 * @email HURRICANE@nb.com
 * @date 2022-05-07 10:44:16
 */
@RestController
@RequestMapping("warehouseManagement/repository")
public class RepositoryController {
    @Autowired
    private RepositoryService repositoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("warehouseManagement:repository:list")
    public R list(@RequestParam Map<String, Object> params){

        // 拿取全部的仓库列表
        PageUtils page = repositoryService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 全部列表
     */
    @RequestMapping("/allList")
    @RequiresPermissions("warehouseManagement:repository:list")
    public R allList(){
        // 拿到所有的仓库对象
        List<RepositoryEntity> list = repositoryService.selectAll();

        return R.ok().put("list", list);
    }

    /**
     * 根据起始地去数据库中拿到仓库
     */
    @RequestMapping("/allListByStartAddress")
    @RequiresPermissions("warehouseManagement:repository:list")
    public R allListByStartAddress(@RequestParam("address") String address){

        // 拿到所有的仓库对象 根据startAddress
        List<RepositoryEntity> list = repositoryService.selectAllByStartAddress(address);

        return R.ok().put("list", list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("warehouseManagement:repository:info")
    public R info(@PathVariable("id") Integer id){

		RepositoryEntity repository = repositoryService.getById(id);

        return R.ok().put("repository", repository);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("warehouseManagement:repository:save")
    public R save(@RequestBody RepositoryEntity repository){
        // 保存到数据库
		repositoryService.insertRepositoryEntity(repository);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("warehouseManagement:repository:update")
    public R update(@RequestBody RepositoryEntity repository){

		repositoryService.updateById(repository);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("warehouseManagement:repository:delete")
    public R delete(@RequestBody Integer[] ids){

		repositoryService.removeRepositoryByIds(Arrays.asList(ids));

        return R.ok();
    }

}
